<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/3/17
  Time: 13:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form id="formId"  method="post">
        <input type="hidden" name="id" value="${user.id}"/>
        <table>
            <tr>
                <td>用户名：</td>
                <td><input type="text" name="name"  value="${user.name}" /></td>
            </tr>
            <tr>
                <td>密码：</td>
                <td><input type="text" name="password"  value="${user.password}"/></td>
            </tr>
            <tr>
                <td>年龄：</td>
                <td><input type="text" name="age"  value="${user.age}"/></td>
            </tr>
            <tr>
                <td>地址：</td>
                <td><input type="text" name="address"  value="${user.address}"/></td>
            </tr>
            <tr>
                <td><input type="button" onclick="submitForm()" value="添加"/></td>
            </tr>
        </table>
    </form>

    <script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js"></script>
    <script src="<%=request.getContextPath()%>/static/layer/layer.js"></script>
    <script src="<%=request.getContextPath()%>/static/mylayer.js"></script>
    <script>
        function submitForm() {
            $.post(
                '<%=request.getContextPath()%>/user?method=update',
                $('#formId').serialize(),
                function(jsonResult) {
                    console.log(jsonResult);
                    if (jsonResult.ok) {
                        mylayer.okMsg(jsonResult.msg)
                        //关闭弹出框
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //刷新父页面
                        window.parent.location.reload();
                    } else {
                        mylayer.errorMsg(jsonResult.msg);
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
